package com.example.instrumentationdemo;

import android.content.Context;

import androidx.test.espresso.Espresso;
import androidx.test.platform.app.InstrumentationRegistry;
import androidx.test.ext.junit.runners.AndroidJUnit4;
import androidx.test.rule.ActivityTestRule;

import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;

import static androidx.test.espresso.Espresso.onView;
import static androidx.test.espresso.action.ViewActions.clearText;
import static androidx.test.espresso.action.ViewActions.click;
import static androidx.test.espresso.action.ViewActions.typeText;
import static androidx.test.espresso.assertion.ViewAssertions.matches;
import static androidx.test.espresso.matcher.ViewMatchers.isDisplayed;
import static androidx.test.espresso.matcher.ViewMatchers.withId;
import static androidx.test.espresso.matcher.ViewMatchers.withInputType;
import static org.junit.Assert.*;

/**
 * Instrumented test, which will execute on an Android device.
 *
 * @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
 */
@RunWith(AndroidJUnit4.class)
public class ExampleInstrumentedTest {


    @Rule
    public ActivityTestRule<MainActivity> mActivityRule = new ActivityTestRule(MainActivity.class);

    @Test
    public void useAppContext() {
        // Context of the app under test.
//        Context appContext = InstrumentationRegistry.getInstrumentation().getTargetContext();
//        assertEquals("com.example.instrumentationdemo", appContext.getPackageName());


        onView(withId(R.id.et1)).perform(clearText());
        onView(withId(R.id.et2)).perform(clearText());
        onView(withId(R.id.et1)).perform(typeText("123"));
        onView(withId(R.id.et2)).perform(typeText("456"));
        onView(withId(R.id.et3)).perform(typeText("789"));
        onView(withId(R.id.btn)).perform(click()).check(matches(isDisplayed()));


        try {
            Thread.sleep(5000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

        onView(withId(R.id.edit_text)).perform(typeText("test"));

//        onView(withId(R.id.et1)).perform(clearText());
//        onView(withId(R.id.et2)).perform(clearText());
//        onView(withId(R.id.et1)).perform(typeText("856"));
//        onView(withId(R.id.et2)).perform(typeText("32"));
//        onView(withId(R.id.btn)).perform(click());
//
//
//        onView(withId(R.id.et1)).perform(clearText());
//        onView(withId(R.id.et2)).perform(clearText());
//        onView(withId(R.id.et1)).perform(typeText("777"));
//        onView(withId(R.id.et2)).perform(typeText("14"));
//        onView(withId(R.id.btn)).perform(click());
    }
}
